﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Secretaria_NotasConceptuales : System.Web.UI.Page
{
    DataTable dtNotaSig;
    protected void Page_Load(object sender, EventArgs e)
    {
        //obtengo el significado de las nota
        dtNotaSig = Colegio.Tabla("select numero, letra from tiponotas where idioma = 1");
        CboReunion.seleciona += new cboSelected(CboReunion_seleciona);
        CboCursos.seleciona += new cboSelected(CboCursos_seleciona);

        if (!IsPostBack)
        {
            FillCboReuniones();
            FillCboCursos();
        }
    }

    void CboReunion_seleciona(string param1, string param2)
    {
        ShowNotasConcepto();
    }

    void CboCursos_seleciona(string param1, string param2)
    {
        ShowNotasConcepto();
    }
    private void FillCboReuniones()
    {
        CboReunion.SourceData = "Proc_getReunionesConcepto ";
        CboReunion.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        CboReunion.NameId = "Id";
        CboReunion.NameDescript = "Detalle";
        CboReunion.BindCBO();

    }
    private void FillCboCursos()
    {
        CboCursos.SourceData = "select idCurso, CursoDescrip from curso order by 1";
        CboCursos.TipoOrigen = Controles_cboGeneric.TipoSource.Procedure;
        CboCursos.NameId = "IdCurso";
        CboCursos.NameDescript = "CursoDescrip";
        CboCursos.BindCBO();
    }
    protected void cmdGuardar_Click(object sender, EventArgs e)
    {
        ShowNotasConcepto();
    }

    private void ShowNotasConcepto()
    {
        if (CboCursos.ValueInt > 0 && CboReunion.ValueInt > 0)
        {
            XmlDataAlumnos ds = new XmlDataAlumnos();
            GridView1.DataSource = ds.getConceptual(CboCursos.ValueInt, CboReunion.ValueInt);
            GridView1.DataBind();
        }
    }


    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        
        //en el header
        if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.Header) {
            int cols = e.Row.Cells.Count;

            for (int iCol = 2; iCol < 5; iCol++)
            {
                e.Row.Cells[iCol].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[iCol].Style["filter"] = "flipv fliph";
                e.Row.Cells[iCol].Style["width"] = "50px";
            }

            for (int iCol = 5; iCol < e.Row.Cells.Count - 2; iCol ++)
            {
                e.Row.Cells[iCol].Text = e.Row.Cells[iCol].Text.Substring(0,e.Row.Cells[iCol].Text.Length-1);
                e.Row.Cells[iCol].ColumnSpan = 2;
                e.Row.Cells[iCol].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[iCol].Style["filter"] = "flipv fliph";
                e.Row.Cells[iCol].Style["width"] = "50px";
                e.Row.Cells.Remove(e.Row.Cells[iCol+1]);

            }
            
                e.Row.Cells[e.Row.Cells.Count-2].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[e.Row.Cells.Count-2].Style["filter"] = "flipv fliph";
                e.Row.Cells[e.Row.Cells.Count - 2].Style["width"] = "50px";
                e.Row.Cells[e.Row.Cells.Count-1].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[e.Row.Cells.Count-1].Style["filter"] = "flipv fliph";
                e.Row.Cells[e.Row.Cells.Count - 1].Style["width"] = "50px";
            
        }

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            
            for (int iCol = 5; iCol < e.Row.Cells.Count ; iCol ++)
            {
                Decimal iValue;
                if(Decimal.TryParse(e.Row.Cells[iCol].Text,out iValue)){
                    
                    e.Row.Cells[iCol].CssClass = "nc" + (int)iValue;
                    if ((int)iValue > 0)
                    {
                        e.Row.Cells[iCol].Text = (dtNotaSig.Select("Numero = " + ((int)iValue).ToString()))[0]["Letra"].ToString();
                    }
                    else { e.Row.Cells[iCol].Text = "A"; }

             
                }
            }
        }
    }

    
}
